/**
 *
 */
package com.qzxl.conntext.utils;

import org.springframework.http.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;

/**
 * @Auther: jintianyun
 * @Date: 2020/3/19 11:15
 * @Description:
 */
public class HttpClientUtils {

    /**
     * TODO
     * httpclienutil
     * @param
     *
     */

    public static ResponseEntity<String> SendHttp(String url, String json, String method, HttpHeaders headers) {
        RestTemplate rest = new RestTemplate();
        //url=url+"?username=administrator&password=YYxq123++";
        //System.out.println("sadasdasdasadadasda: "+url);
        HttpEntity<String> Entity = new HttpEntity<String>(json, headers);
        return rest.exchange(url, HttpMethod.valueOf(method), Entity, String.class);
    }

    public static HttpHeaders SetHeaders(HashMap<String, String> auth) {
        HttpHeaders headers = new HttpHeaders();

        if (auth == null) {
            headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
            headers.add("Accept", MediaType.APPLICATION_JSON.toString());

        } else {
            headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
            Set<Entry<String, String>> set = auth.entrySet();
            for (Entry<String, String> entry : set) {
                headers.add(entry.getKey(), entry.getValue());
            }
        }
        return headers;
    }


}
